package com.franzliszt.OrderOnline.Activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.franzliszt.OrderOnline.sunzhengyi.LoginPackage.Login;
import com.franzliszt.OrderOnline.util.KillProcess;
import com.franzliszt.hospitalnumberingsystem.R;



/**
 * Author:FranzLiszt
 * Completion time:9-20*/

public class WelComeActivity extends AppCompatActivity {
    private Button btn_Skip,GetInto;
    private int TotalNumber = 5;
    /*用于点击跳过或者进入应用按钮之后，界面发生跳转，但线程并未停止，时间到达，仍会重新渲染一次，
    使用此标志，用来控制不执行异步介绍的信息，从此达到中断的效果*/
    private boolean Flag = true;
    private KillProcess killProcess;
    Handler handler = new Handler(  ){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage( msg );
            if (msg.what == 0 && Flag) {
                int Count = CountDown();
                btn_Skip.setText( "跳过 " + Count );
                handler.sendEmptyMessageDelayed( 0,1000 );
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE );
            getWindow().setStatusBarColor( Color.TRANSPARENT );
        }
        setContentView( R.layout.activity_wel_come );
        InitView();
    }
    /*5s之后自动跳转*/
    private void InitView(){
        btn_Skip = findViewById( R.id.btn_Skip );
        GetInto = findViewById( R.id.GetInto);
        handler.sendEmptyMessageDelayed( 0,1000 );
        killProcess = KillProcess.getInstance();
        killProcess.addActivity( WelComeActivity.this );
    }
    private int CountDown(){
        if (TotalNumber -- == 1){
            ReturnActivity(Login.class);
        }
        return TotalNumber;
    }

    public void Skip(View view) {
        Flag = false;
        ReturnActivity(Login.class);
    }

    public void GetIntoApp(View view) {
        Flag = false;
        ReturnActivity(Login.class);
    }
    private void ReturnActivity(Class Activity){
        startActivity( new Intent( WelComeActivity.this,Activity ) );
    }
}
